﻿#include "FITKPhyscisPropertyRibbed.h"
#include "FITKPhyscisPropertyRibInfo.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppSettings.h"
#include <QColor>

namespace Acoustics
{
    FITKPhyscisPropertyRibbed::FITKPhyscisPropertyRibbed()
    {
        //创建对象，最多两个方向，第二方向可以设置为无效
        _ribInfo1 = new FITKPhyscisPropertyRibInfo;
        _ribInfo2 = new FITKPhyscisPropertyRibInfo;
        this->updateDefaultColor();
    }

    FITKPhyscisPropertyRibbed::~FITKPhyscisPropertyRibbed()
    {
        //释放内存
        if (_ribInfo1) delete _ribInfo1;
        if (_ribInfo2) delete _ribInfo2;
    }

    FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType FITKPhyscisPropertyRibbed::getPhysicsPropType()
    {
        //仓库中获取对象
         return AcousticsPhyscisPropType::APPRibbedphysicalProperty;
    }

    double FITKPhyscisPropertyRibbed::getBaseAngle() const
    {
        return _baseAngle;
    }

    void FITKPhyscisPropertyRibbed::setBaseAngle(double baseAngle)
    {
        _baseAngle = baseAngle;
    }

    void FITKPhyscisPropertyRibbed::setSkinPropID(const int id)
    {
        _skinPropID = id;
    }


    int FITKPhyscisPropertyRibbed::getSkinPropID()
    {
        return _skinPropID;
    }

    FITKAcousticsAbsPhysicsProp* FITKPhyscisPropertyRibbed::getSkinPropObj()
    {
        //仓库中获取对象
        return FITKDATAREPO->getTDataByID<FITKAcousticsAbsPhysicsProp>(_skinPropID);
    }

    bool FITKPhyscisPropertyRibbed::isDir2Enabled()
    {
        //错误判断
        if (_ribInfo2 == nullptr) return false;
        //属性ID小于等于0，无效
        return _ribInfo2->getBeamPropID() > 0;
    }

    Acoustics::FITKPhyscisPropertyRibInfo* FITKPhyscisPropertyRibbed::getDri1RibInfo()
    {
        return _ribInfo1;
    }

    Acoustics::FITKPhyscisPropertyRibInfo* FITKPhyscisPropertyRibbed::getDri2RibInfo()
    {
        return _ribInfo2;
    }

    double FITKPhyscisPropertyRibbed::getShellThickness()
    {
        //获取加筋板的基板厚度 - 基板只有均质板和自由阻尼板
        FITKAcousticsAbsShellPhysicsProp* shellPhyProp = dynamic_cast<FITKAcousticsAbsShellPhysicsProp*>(this->getSkinPropObj());
        if (!shellPhyProp || shellPhyProp->getPhysicsPropType() == Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPRibbedphysicalProperty)
            return 0.0;
        return shellPhyProp->getShellThickness();
    }

    void FITKPhyscisPropertyRibbed::updateDefaultColor()
    {
        //获取软件设置
        AppFrame::FITKAppSettings* settings = FITKAPP->getAppSettings();
        if (!settings) return;
        //获取配置
        QVariant ribbed = settings->getVarient("RibbedPhyProp");
        //更新加筋板材料颜色
        if (ribbed.isNull())
        {
            ribbed = settings->getVarient("OriRibbedPhyProp");
            if (ribbed.isNull()) return;
        }
        QColor ribbedColor = ribbed.value<QColor>();
        _color[0] = ribbedColor.redF();
        _color[1] = ribbedColor.greenF();
        _color[2] = ribbedColor.blueF();
    }

}
